//
//  AppDelegate.m
//  WeiBo
//
//  Created by Apple_Lzzy46 on 16/9/12.
//  Copyright © 2016年 LTL. All rights reserved.
//
#import "AppDelegate.h"
#import "LTLTabBarController.h"
#import "LTLModel.h"
#import "LTLNewCharacteristics.h"
#import "LTLAdvertisement.h"

@interface AppDelegate ()


@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    ///创建窗口
    self.window                                  = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    ///指定窗口根控制器
//    LTLTabBarController *taber                   = [[LTLTabBarController alloc]init];
    
//    LTLNewCharacteristics *new = [[LTLNewCharacteristics alloc]init];
//
//    self.window.rootViewController               = new;
    [self isNetWorkReachable];
    
    [self.window rootView];
//    [LTLSpeechTool creatSpeechWithSpeechText:@"欢迎使用李泰良开发的微博!"];
    ///让窗口显示
    [self.window makeKeyAndVisible];
    /**
     *  显示广告
     */
    [self DisplayAds];
    [self zhuTi];
    return YES;
}
///设置主题色
-(void)zhuTi
{
    [UINavigationBar appearance].tintColor       = [UIColor orangeColor];
    [UITabBar appearance].tintColor              = [UIColor orangeColor];
    [UINavigationBar appearance].backgroundColor = [UIColor clearColor];
}

// 接收到内存警告就会调用
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
    //    DDActionLog;
    
    // 1.停止当前下载
    [[SDWebImageManager sharedManager] cancelAll];
    
    // 2.清空内存缓存
    [[SDWebImageManager sharedManager].imageCache clearMemory];
}

- (BOOL)isNetWorkReachable{
    // 1.创建AFN网络管理者
    AFNetworkReachabilityManager *afNetworkReachabilityManager = [AFNetworkReachabilityManager sharedManager];
    // 2.开启网络监视器；
    [afNetworkReachabilityManager startMonitoring];
    [afNetworkReachabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status)
     {
         switch (status) {
             case AFNetworkReachabilityStatusNotReachable:{
                 NSLog(@"网络不通");
                 break;
             }
             case AFNetworkReachabilityStatusReachableViaWiFi:{
                 
                 NSLog(@"网络通过WIFI连接");
                 break;
             }
             case AFNetworkReachabilityStatusReachableViaWWAN:{
                 
                 NSLog(@"网络通过流量连接");
                 break;
             }
             default:
                 
                 break;
         }
     }];
    return [AFNetworkReachabilityManager sharedManager].isReachable;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
///从后台进入前台
- (void)applicationWillEnterForeground:(UIApplication *)application {
   
    [self DisplayAds];
    
}
-(void)DisplayAds
{
    NSString *image = @"http://a1.qpic.cn/psb?/V10Tln6i1Eq6sm/jbRM3GNNFx59.B21r8*1.XUX0p2FkusmCiAm4MntFOY!/b/dPgAAAAAAAAA&ek=1&kp=1&pt=0&bo=gAI3BDgEHAcFCL0!&sce=0-12-12&rf=viewer_311";
    NSString *ad = @"http://weibo.com/";
    
    LTLAdvertisement *guangGao = [[LTLAdvertisement alloc]initWithFrame:[UIScreen mainScreen].bounds imgUrl:image adUrl:ad clickImg:^(NSString *clikImgUrl) {
        
    }];
    
    //设置倒计时（默认3秒）
    guangGao.showTime = 5;
    
    //2、显示广告
    [guangGao show];


}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
